package com.nowcoder.community.util;

import com.nowcoder.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * 持有客户端当前登录的用户信息，用于代替session。
 */
@Component
public class HostHolder {

    private final ThreadLocal<User> loginUser = new ThreadLocal<>();

    public User getUser() {
        return loginUser.get();
    }

    public void setUser(User user) {
        loginUser.set(user);
    }

    public void clearUser() {
        loginUser.remove();
    }

}
